package com.acme.service.bank.impl;

import java.util.List;
import com.acme.domain.account.Account;
import com.acme.domain.client.Bank;
import com.acme.service.bank.BankReportPresentationService;
import com.acme.service.bank.BankReportService;

public class ConsoleBankReportPresentationService implements
		BankReportPresentationService {
	
	private BankReportService bankReportService;

	@Override
	public void printNumberOfClients(Bank bank) {
		System.out.println(String.format("Number of clients: %d\n", bankReportService.getNumberOfClients(bank)));
	}

	@Override
	public void printNumberOfOpenedAccounts(Bank bank) {
		int number = bankReportService.getNumberOfOpenAccounts(bank);
		System.out.println(String.format("Number of opened accounts: %d", number));
	}

	@Override
	public void printAccountsSortedByDeposit(Bank bank, boolean ascending) {
		List<Account> accounts = bankReportService.getAccountsSortedByDeposit(bank, true);
		StringBuffer sb = new StringBuffer();
		sb.append("* Accounts sorted by deposit *\n");
		for(Account account: accounts) {
			sb.append(String.format("Account #%d type %s balance %f\n", account.getAccountNumber(), account.getAccountType(), account.getBalance()));
		}
		System.out.println(sb);
	}

	@Override
	public void printClientsAccounts(Bank bank) {
		List<Account> accounts = bankReportService.getCustomerAccounts(bank);
		StringBuffer sb = new StringBuffer();
		sb.append("* Clients accounts *\n");
		for(Account acc: accounts) {
			sb.append(String.format("account #%d type %s", acc.getAccountNumber(), acc.getAccountType()));
		}
		System.out.println(sb.toString());
	}

	@Override
	public void setBankReportService(BankReportService bankReportService) {
		this.bankReportService = bankReportService;
	}
}
